package model

import (
	"XSSS_v2/pkg/auth"
	"github.com/go-playground/validator/v10"
)

func (stu *Student) CreateStu() error {
	return DB.Create(stu).Error
}
func GetAStu(sno string) (*Student, error) {
	student := Student{}
	return &student, DB.Where("sno = ?", sno).First(&student).Error
}

func GetAllStu() (totalCount int64, students []*Student, err error) {
	res := DB.Find(&students)
	return res.RowsAffected, students, res.Error
}
func DeleteStu(id int) error {
	stu := Student{}
	stu.BaseModel.Id = id
	return DB.Delete(&stu).Error
}
func (s *Student) UpdateStu() error {
	return DB.Save(s).Error
}
func (stu *Student) Validate() error {
	validate := validator.New()
	return validate.Struct(stu)
}
func (stu *Student) Encrypt() (err error) {
	stu.Spwd, err = auth.Encrypt(stu.Spwd)
	return
}
